// Mock数据 - 用于开发环境模拟后端数据
import { apiConfig } from './config'

// 模拟延迟
const delay = (ms = 1000) => new Promise(resolve => setTimeout(resolve, ms))

// Mock数据
export const mockData = {
  // 用户相关Mock数据
  user: {
    // 登录Mock
    login: async (data) => {
      await delay(800)
      if (data.username === 'admin' && data.password === '123456') {
        return {
          code: 200,
          success: true,
          message: '登录成功',
          data: {
            token: 'mock-token-123456',
            userInfo: {
              id: 1,
              username: 'admin',
              nickname: '管理员',
              avatar: 'https://img.yzcdn.cn/vant/cat.jpeg',
              phone: '18888888888'
            }
          }
        }
      } else {
        return {
          code: 400,
          success: false,
          message: '用户名或密码错误'
        }
      }
    },

    // 获取用户信息Mock
    getUserInfo: async () => {
      await delay(500)
      return {
        code: 200,
        success: true,
        data: {
          id: 1,
          username: 'admin',
          nickname: '管理员',
          avatar: 'https://img.yzcdn.cn/vant/cat.jpeg',
          phone: '18888888888'
        }
      }
    }
  },

  // 上报相关Mock数据
  report: {
    // 获取上报列表Mock
    getReportList: async (params) => {
      await delay(800)
      const list = [
        {
          id: 1,
          address: "10号楼1011",
          reportTime: "2025-11-10 14:30",
          status: "pending",
          description: "水管漏水，需要维修",
          images: ["https://img.yzcdn.cn/vant/cat.jpeg"],
          createTime: "2025-11-10 14:30:00"
        },
        {
          id: 2,
          address: "10号楼1011",
          reportTime: "2025-11-09 14:30",
          status: "processing",
          description: "电梯故障",
          images: [],
          createTime: "2025-11-09 14:30:00"
        },
        {
          id: 3,
          address: "10号楼1011",
          reportTime: "2025-11-08 14:30",
          status: "completed",
          description: "门锁损坏",
          images: ["https://img.yzcdn.cn/vant/cat.jpeg"],
          createTime: "2025-11-08 14:30:00"
        }
      ]

      return {
        code: 200,
        success: true,
        data: {
          list,
          total: list.length,
          pageNum: params.pageNum || 1,
          pageSize: params.pageSize || 10
        }
      }
    },

    // 创建上报Mock
    createReport: async (data) => {
      await delay(1000)
      return {
        code: 200,
        success: true,
        message: '上报成功',
        data: {
          id: Date.now(),
          ...data,
          status: 'pending',
          createTime: new Date().toISOString()
        }
      }
    },

    // 更新上报Mock
    updateReport: async (id, data) => {
      await delay(800)
      return {
        code: 200,
        success: true,
        message: '更新成功',
        data: {
          id,
          ...data,
          updateTime: new Date().toISOString()
        }
      }
    },

    // 删除上报Mock
    deleteReport: async (id) => {
      await delay(500)
      return {
        code: 200,
        success: true,
        message: '删除成功'
      }
    }
  }
}

// 拦截请求，返回Mock数据
export function useMock() {
  if (!apiConfig.mock) return

  // 这里可以使用 mock.js 或其他Mock库
  console.log('🚀 Mock模式已启用')
} 